﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using ThoiTrang.Business;
using ThoiTrang.Entities;
using System.Drawing;
using System.Xml;

public partial class detail_print : System.Web.UI.Page
{
    public a_Articles_ImgCollection imgs;

    public a_Article art;
    public a_Articles_Img mainImg;
    public a_CatMain catMain;
    public a_CatSub catSub;
    public a_ArticleCollection artNewr;
    public a_ArticleCollection artLaster;
    public a_Articles_ImgCollection img2s;
    public a_SEO_Content seoContent;

    public string mImg;
    public string titleImg;

    public string strContent;
    public string strFooter;
    public string strOtherPost;
    public string ckid;
    protected void Page_Load(object sender, EventArgs e)
    {
        Page.Title = "Thoi trang-thoitrang.com";
        ckid = Request["ckid"];
        SessionManager.SetCookie(ckid);
        if (Request["aid"] != null)
        {
            try
            {

                    art = a_ArticleService.Geta_Article(int.Parse(Request["aid"]));
                    catMain = a_CatMainService.Geta_CatMain(art.MainCatID);
                    mainImg = a_Articles_ImgService.Geta_Articles_ImgMainByAID(art.ID);
                    catSub = a_CatSubService.Geta_CatSub(art.SubCatID);
                    //img2s = a_Articles_ImgService.Geta_Articles_ImgListByAID(int.Parse(Request["aid"]), a_Articles_ImgColumns.ImageNo, ThoiTrang.Data.OrderDirection.ASC, page, 8, out total);

                    if (mainImg == null) return;

                    strContent = GeneralContent();
                    Page.Title = art.KTitle;


                emailFriend.HRef = "emailFriend.aspx?dt=2&aid=" + Request["aid"] + "&ckid=" + SessionManager.GetCookie();
                emailFriend1.HRef = "emailFriend.aspx?dt=2&aid=" + Request["aid"] + "&ckid=" + SessionManager.GetCookie();
                strContent = strContent.Replace("ckid=", "ckid=" + ckid);
            }
            catch (Exception ex)
            {
                Response.Write(ex.Message);
            }
        }
        
    }
    public string GeneralContent()
    {
        string kq = @"<div class=""top""><h3><img src=""<%=titleImg%>"" alt=""thoi trang"" height=""40"" /></h3>
                    <div class=""print"">
                        <input class=""btnGo"" type=""button"" value=""In Trang"" onClick=""window.print();"" />
                    </div>
                </div>
					<div class=""detail-object"" <%=displayContent%>>
						<div class=""detail-des"">
							<div class=""detail-pic fl"">
								<div class=""detail-pic-img""><img src=""<%=mImg%>"" alt=""thoi trang""  /></div>
							</div>
							<h5><%=art.UTitle%></h5>
							<p class=""detail-detail-content""><%=art.UBody%></p>
							<p class=""author""><%=art.UAuthor%></p>
						</div>
					</div>";
        mImg = FOConstants.Dir_ImgArticle + art.KTitle.Replace(' ', '-') + "-" + mainImg.FYear.ToString() + "-" + "d" + mainImg.AID.ToString() + mainImg.ImageNo.ToString() + ".jpg";
        string linkEcard = "ecard.aspx?dt=3&iid=" + mainImg.IID.ToString() + "&in=" + art.KTitle.Replace(' ', '-') + "-" + mainImg.FYear.ToString() + "-" + "d" + mainImg.AID.ToString() + mainImg.ImageNo.ToString() + ".jpg" + "&o=v&aid=" + mainImg.AID.ToString() + "&ckid=";
//        if (art.LayoutFormat == FOConstants.LstStandar)
//            kq = kq.Replace("<%=ToolImage%>", @"<p class=""guithiepso fl""><a href=""#"">Gửi thiệp số</a></p>
//									<p class=""luualbum fl""><a href=""#"">Lưu album</a></p>
//									<p class=""danhgia fl""><a href=""#"">Đánh giá</a></p>");
//        else
//            kq = kq.Replace("<%=ToolImage%>", "<p class=\"danhgia fl\"><a href=\"download.aspx?in=" + mImg + "\">Tải avatar</a></p>");

        titleImg = FOConstants.Dir_ImgTitle + catSub.Name.Replace(' ', '-') + "-hp.gif";
        kq = kq.Replace("<%=titleImg%>", titleImg);
        kq = kq.Replace("<%=mImg%>", mImg);
        kq = kq.Replace("<%=art.UTitle%>", art.UTitle);
        kq = kq.Replace("<%=mainImg!=null?mainImg.IID:0%>", mainImg != null ? mainImg.IID.ToString() : "0");
        kq = kq.Replace("<%=art.UAuthor%>", art.UAuthor);
        kq = kq.Replace("<%=art.UBody%>", art.UBody);
        string dp = (Request["cp"] != null && Request["cp"] != "1") ? "style=\"display:none;\"" : "";
        kq = kq.Replace("<%=displayContent%>", dp);
        kq = kq.Replace("<%=art.ID%>", art.ID.ToString());
        kq = kq.Replace("<%=SessionManager.GetCookie()%>", "");
        return kq;
    }
   
    public string GetString(int aid)
    {
        string html = "";
        a_Article aTemp = a_ArticleService.Geta_Article(aid);
        int total;
        a_Articles_ImgCollection imgs = a_Articles_ImgService.Geta_Articles_ImgListByAID(aid, a_Articles_ImgColumns.ImageW, ThoiTrang.Data.OrderDirection.ASC, 0, 0, out total);
        if (imgs != null)
        {
            switch (aTemp.LayoutFormat)
            {
                case FOConstants.LstStandar:
                    html = lstImgStandar(imgs, aTemp);
                    break;
                case FOConstants.LstAvatar:
                    html = lstImgAvatar(imgs, aTemp);
                    break;
                default:
                    html = lstImgStandar(imgs, aTemp);
                    break;
            }
        }
        else
            html += "<div class=\"detail-full\"><p align=\"center\">Không có dữ liệu hiển thị!</p><div class=\"clear\"></div></div>";

        return html;
    }
    protected string lstImgStandar(a_Articles_ImgCollection imgs, a_Article aTemp)
    {
        string html = "<div class=\"detail-full\">";
        foreach (a_Articles_Img Img in imgs.ToArray())
        {
            string link = FOConstants.Dir_ImgArticle + aTemp.KTitle.Replace(' ', '-') + "-" + Img.FYear.ToString() + "-" + "d" + Img.AID.ToString() + Img.ImageNo.ToString() + ".jpg";
            int width = (Img.ImageW != null && Img.ImageW > 0) ? Img.ImageW : 250;
            string img = "<div class=\"detail-pic fl\">";
            img += "<div class=\"detail-pic-img\"><img src=\"" + link + "\" alt=\"thoi trang\" width=\"" + width.ToString() + "\"  /></div>";
            img += "</div>";
            html += img;
        }
        html += "<div class=\"clear\"></div></div>";
        return html;
    }
    protected string lstImgAvatar(a_Articles_ImgCollection imgs, a_Article aTemp)
    {
        string html = "<div class=\"detail-full avatar\">";
        foreach (a_Articles_Img Img in imgs.ToArray())
        {
            string link = FOConstants.Dir_ImgArticle + aTemp.KTitle.Replace(' ', '-') + "-" + Img.FYear.ToString() + "-" + "d" + Img.AID.ToString() + Img.ImageNo.ToString() + ".jpg";
            int width = (Img.ImageW != null && Img.ImageW > 0) ? Img.ImageW : 250;
            string img = "<div class=\"detail-pic fl\">";
            img += "<div class=\"detail-pic-img\"><img src=\"" + link + "\" alt=\"thoi trang\" width=\"" + width.ToString() + "\" /></div>";
            img += "</div>";
            html += img;
        }
        html += "<div class=\"clear\"></div></div>";
        return html;
    }
}
